package com.joe.utils;

import java.util.Arrays;
import java.util.Collection;

/**
 * Created by joe on 2019/1/27
 */
public class PPrint {

    /**
     * 打印
     */
    public static void print(Collection<?> collection) {
        System.out.print(format(collection));
    }

    /**
     * 打印后换行
     */
    public static void println(Collection<?> collection) {
        System.out.println(format(collection));
    }

    /**
     * overwrite
     */
    public static void print(Object[] objArr) {
        System.out.print(format(Arrays.asList(objArr)));
    }

    /**
     * overwrite
     */
    public static void println(Object[] objArr) {
        System.out.println(format(Arrays.asList(objArr)));
    }


    private static String format(Collection<?> collection) {
        if (CollectionUtils.isEmpty(collection)) {
            return "[]";
        }
        StringBuilder sb = new StringBuilder("[");
        for (Object obj : collection) {
            if (collection.size() > 1) {
                sb.append("\n\t");
            }
            sb.append(obj);
        }
        if (collection.size() > 1) {
            sb.append("\n");
        }
        sb.append("]");
        return sb.toString();
    }

}
